package com.test002;

import java.awt.BorderLayout;
import java.awt.Color;
import java.awt.Dimension;
import java.awt.FlowLayout;
import java.awt.Font;
import java.awt.event.MouseAdapter;
import java.awt.event.MouseEvent;
import java.awt.image.BufferedImage;
import java.io.IOException;
import java.util.HashMap;
import java.util.Map;
import javax.imageio.ImageIO;
import javax.swing.BorderFactory;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JPanel;
import javax.swing.JTextPane;
import javax.swing.border.TitledBorder;

/**
 * @author zhoumingyan
 * @date 2020年3月5日 下午1:44:15
 */
public class Caculator extends JFrame {
	private static final long serialVersionUID = 1L;
	/**
	 * 属性
	 */
	Font f1 = new Font("宋体",Font.PLAIN,18);
	Font f2 = new Font("宋体",Font.PLAIN,14);
	
	String iconImgpath = "./static/images/2.png";
	
	JPanel mainPanel = new JPanel();
	JPanel btnpPanel = new JPanel();
	int count = 0;
	Map<String,String> maps = new HashMap<String,String>() {
		private static final long serialVersionUID = 1L;
		{
			put("阿里巴巴总部地址","哈哈哈哈哈哈哈哈哈哈哈哈啊哈哈哈哈哈哈啊哈哈哈哈哈");
			put("中国百度总公司地址","www.baidu.com");
			put("倾斜摄影转3dtail","www.baidu.com");
			put("众越正式环境","chinaxf.njzycn.com");
		}
	};

	public static void main(String[] args) {
		new Caculator();

	}
	
	public Caculator() {
		 init();
	}
	
	/**
	 * @Description:初始化
	 * @author: zhoumingyan
	 * @date 2020年3月6日 上午11:24:28
	 */
	public void init() {
		pagTable();
		setMenuDatas();
		
	}
	
	/**
	 * @Description:创建可视化窗口
	 * @author: zhoumingyan
	 * @date 2020年3月6日 上午11:23:47
	 */
	public void pagTable() {
		BufferedImage icon = null;  
		try {  
			icon = ImageIO.read(this.getClass().getResource(iconImgpath));  
		} catch (IOException e) {  
			e.printStackTrace();  
		}  
		this.setIconImage(icon);
		this.setDefaultCloseOperation(EXIT_ON_CLOSE);
		this.setVisible(true);
		this.setSize(1530,960);
		this.setLocationRelativeTo(null);
		this.setTitle("周明岩-控制台");
		btnpPanel.setLayout(null);
		btnpPanel.setPreferredSize(new Dimension(260, 960));
		btnpPanel.setBorder( BorderFactory.createTitledBorder("菜单") );
		mainPanel.setLayout(null);
		mainPanel.setPreferredSize(new Dimension(2000, 960));
		TitledBorder tb = BorderFactory.createTitledBorder("内容");  
        tb.setTitleJustification(TitledBorder.RIGHT);  
        mainPanel.setBorder(tb); 
		btnpPanel.setBackground(Color.WHITE);
		mainPanel.setBackground(Color.WHITE);
		this.add(btnpPanel, BorderLayout.WEST);
		this.add(mainPanel, BorderLayout.EAST);
	}
	
	/**
	 * 菜单赋值
	 * @Description:
	 * @author: zhoumingyan
	 * @date 2020年3月6日 上午11:20:16
	 */
	public void setMenuDatas() {
		maps.forEach((k, v) -> {
			count++;
			JLabel label =  new JLabel(k); 
			label.setFont(f2);
			label.setOpaque(true);
			label.setBackground(Color.LIGHT_GRAY);
			label.setForeground(Color.BLACK);//可以直接设置文字颜色
			label.setBounds(18, 30*count, 220, 25);
			label.addMouseListener(new MouseAdapter(){
				//鼠标点击事件
				public void mouseClicked(MouseEvent e){
			    	label.setBackground(Color.lightGray);
			    	JTextPane jp = new JTextPane();
			    	jp.setContentType("text/html");
			    	jp.setFont(f1);
			    	jp.setText(v);
			    	jp.setBounds(750, 30, 1240, 880);
			    	//jp.setBackground(Color.LIGHT_GRAY);
			    	mainPanel.add(jp);
			     }
				
				//鼠标按下事件
				public void mousePressed(MouseEvent e) {
					label.setBackground(Color.BLUE);
					label.setForeground(Color.PINK);
				}
				
				//鼠标释放事件
				public void mouseReleased(MouseEvent e) {
					label.setBackground(Color.LIGHT_GRAY);
					label.setForeground(Color.BLACK);
				}

				//鼠标进入事件
				public void mouseEntered(MouseEvent e) {
					label.setBackground(Color.MAGENTA);
				}

				//鼠标离开事件
				public void mouseExited(MouseEvent e) {
					label.setBackground(Color.LIGHT_GRAY);
				}
				//鼠标拖动状态
				public void mouseDragged(MouseEvent e) {
					
				}
				//鼠标移动状态
				public void mouseMoved(MouseEvent e) {
				}
				
			 });
			btnpPanel.add(label);
		  });
		count = 0;
	}
	
}

